package com.itheima.dao;

import java.util.List;

import org.springframework.orm.hibernate5.support.HibernateDaoSupport;

import com.itheima.domain.Customer;

@SuppressWarnings("all")
public class CustomerDao extends HibernateDaoSupport{

	public void saveAdd(Customer customer) {
		this.getHibernateTemplate().save(customer);
	}

	public List<Customer> list() {
		List<Customer> list = (List<Customer>) this.getHibernateTemplate().find("from Customer");
		return list;
	}

	public void delete(Customer customer) {
		this.getHibernateTemplate().delete(customer);
	}

	public Customer find(Customer customer) {
		List<Customer> list = (List<Customer>) this.getHibernateTemplate().find("from Customer");
		return list.get(0);
	}

	public void saveEdit(Customer customer) {
		this.getHibernateTemplate().update(customer);
	}

	public List<Customer> likeSerch(Customer customer) {
		List<Customer> list = (List<Customer>) this.getHibernateTemplate().find("from Customer where custName like ?", "%"+customer.getCustName()+"%");
		return list;
	}

	public Customer findOne(Customer customer) {
		Customer c = this.getHibernateTemplate().get(Customer.class, customer.getCid());
		return c;
	}
}
